<?php


session_start();
require_once('config.php');
require_once('includes.php');

$default_controller= 'Event';
$default_action='month_grid'; 

set_global_default('controller', $default_controller);
set_global_default('action', $default_action);

$cname=$_GET['controller'];
$mname=$_GET['action'];

//load up the controller and call the appropriate action method
try
{
	require_once('classes/controllers/' . strtolower($cname) . ".php");
	$class = new ReflectionClass($cname . 'Controller');
	$controller = $class->newInstance();

	if (!$class->hasMethod($mname))
	{
		// no matching method
		throw new PageNotFoundException;
	}

	$method = $class->getMethod($mname);
	$arguments=array();

	if ($method->isProtected() or $method->isPrivate())
	{
		// no!
		throw new ForbiddenPageException;
	}

	$method->invokeArgs($controller, $arguments);
	
	//good result!
	exit(0);
}
catch (ForbiddenPageException $e)
{
	$error_page = new View('views/403.php');
	echo $error_page;
	
	//bad result!
	exit(1);
}
catch (PageNotFoundException $e)
{
	$error_page = new View('views/404.php');
	echo $error_page;
	
	//bad result!
	exit(1);
}
catch(Exception $e)
{
	$error_page = new View('views/error.php');
	$error_page->error = $e;
	echo $error_page;
	
	//bad result!
	exit(1);
}

?>